import router from "@/router"
import store from "./store"

router.beforeEach(async (to,from,next)=>{
    if(to.path == "/my/MyTab/login"){
        next()
    }else if(to.path == "/shopcart" || to.path=="/my/MyCenter" || to.path=="/my/logOut"){
        let token = store.state.user.token;
        if(token == null || token == ''){
            next("/my/MyTab/login")
        }else{
            try{
                let p = await store.dispatch('checktoken');
                if(p.data.flag){
                    next()
                }else{
                    next("/my/MyTab/login")
                }
            }catch(err){
                console.log(err)
            }
        }
    }else{
        next()
    }
})